package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class Register extends AppCompatActivity {
    private EditText etRegUsername;
    private EditText etRegPassword;
    private RadioButton rbMale;
    private RadioButton rbFemale;
    private EditText etRegAge;
    private Button btnRegSubmit;
    private Button btnRegCancel;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        etRegUsername = findViewById(R.id.et_reg_username);
        etRegPassword = findViewById(R.id.et_reg_password);
        rbMale = findViewById(R.id.rb_male);
        rbFemale = findViewById(R.id.rb_female);
        etRegAge = findViewById(R.id.et_reg_age);
        btnRegSubmit = findViewById(R.id.btn_reg_submit);
        btnRegCancel = findViewById(R.id.btn_reg_cancel);
    }

    public void register(View view) {
        String username = etRegUsername.getText().toString();
        String password = etRegPassword.getText().toString();
        int age =Integer.valueOf(etRegAge.getText().toString());
        boolean gender = rbMale.isChecked();

        String prefName = "com.example.myapplication1";
        SharedPreferences sharedPreferences = getSharedPreferences(prefName,MODE_PRIVATE);
        SharedPreferences.Editor edit =sharedPreferences.edit();
        edit.putString("username" + username,username);
        edit.putString("password" + username,password);
        edit.putBoolean("gender" + username,gender);
        edit.putInt("age" + username,age);
        edit.apply();

        Intent intent = new Intent(this, Login.class);
        intent.putExtra("username",username);
        intent.putExtra("password",password);
        setResult(RESULT_OK,intent);
        finish();


    }

    public void cancel(View view) {
        Intent intent = new Intent(this, Login.class);
        setResult(RESULT_CANCELED,intent);
        finish();
    }
}